#ifndef RECORDLIST_H
#define RECORDLIST_H

#include <QListView>
#include <QStyledItemDelegate>
#include <QAbstractListModel>
#include <QVector>
#include "record.h"

enum CustomRecordListRoles {
    MakeTime = Qt::UserRole + 1,
    VailTime,
    RecordRemark,
    IsExpired,
    IsNeary
};

// ********************* RecordListModel *************************/
class RecordListModel : public QAbstractListModel {
    Q_OBJECT
public:
    explicit RecordListModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;
    Record* getRecord(const QModelIndex &index);

    void LoadItems();

public:
    int total;

private:
    void setupConnections();

private:
    QVector<Record*> records;

private slots:

};

// ********************* MaterialListDelegate *************************/

class RecordListDelegate : public QStyledItemDelegate {
public:
    explicit RecordListDelegate(QListView *parent = nullptr)
        : QStyledItemDelegate(parent) {};

public:
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
    QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override;

    // bool editorEvent(QEvent *event, QAbstractItemModel *model,
    //                              const QStyleOptionViewItem &option,
    //                              const QModelIndex &index) override;

};


class RecordList : public QListView
{
    Q_OBJECT
public:
    explicit RecordList(QWidget *parnet = nullptr);
    void setupConnections();

private:
    RecordListModel model;
    RecordListDelegate* delegate;

private slots:
    void onItemSelected(const QModelIndex& index, const QModelIndex &previous);
};

#endif // RECORDLIST_H
